package com.smit.dvb;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Channel object include channel id,channel name
 *
 * @param <T>
 *
 */
public class ChannelInfo implements Parcelable{

    /**
     * The channel db id,identify the database
     */
    protected byte channelDBId;  //0 ATV, 1 DVBC ,2 DTMB ,etc.

    /**
     * The channel id ,reserve for digital used
     */
    protected int channelId;  // DB Index

    /**
     * The brdcstType , e.g. BRDCST_TYPE_DVB BRDCST_TYPE_DTMB BRDCST_TYPE_ANALOG
     * BRDCST_TYPE_DVB
     *
     */
    //  protected int brdcstType; 与channelDBId功能相同删除

    /**
     * The channel id ,reserve for digital used
     */

    protected int optionMask;  //节目属性，喜好、删除、是否高清、隐藏...

   // protected int serviceType; //业务类型：0 DTV, 1 radio, 2 data  数据广播, 3 NVOD

    /**
     * The channel id ,reserve for digital used
     */
    protected short channelNumber;  //频道号

    /**
     * The service name the length should be less than TVGlobal.MAX_PROG_NAME_LEN
     */
    protected String serviceName;  //频道名称

    protected int frequency;  //kHz

    protected int muxInfoId;

    public ChannelInfo() {
        super();
    }

    public ChannelInfo(byte channelDBId) {
        super();
        this.channelDBId = channelDBId;
        //this.svlRecId = svlRecId;
    }

    public ChannelInfo(byte channelDBId,int channelId,int optionMask,int channelNumber,String serviceName) {
        super();
        this.channelDBId = channelDBId;
        this.channelId = channelId;
        this.optionMask = optionMask;
        this.channelNumber = (short) channelNumber;
        this.serviceName = serviceName;        
        //this.svlRecId = svlRecId;
    }    
    
    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public int getChannelId() {
        return channelId;
    }

    public void setChannelId(int channelId) {
        this.channelId = channelId;
    }

    /**
     * @return the svlId
     */
    public byte getchannelDBId() {
        return channelDBId;
    }

    /**
     * @param svlId
     *            the svlId to set
     */
    public void setchannelDBId(byte channelDBId) {
        this.channelDBId = channelDBId;
    }

    public int getFrequency(){
        return frequency;
    }

    public void setFrequency(int frequency){
        this.frequency = frequency;
    }

    public short getChannelNumber() {
        return channelNumber;
    }

    public void setChannelNumber(short channelNumber) {
        this.channelNumber = channelNumber;
    }

    public int getOptionMask() {
        return optionMask;
    }

    public void setOptionMask(int optionMask) {
        this.optionMask = optionMask;
    }

    public int getMuxInfoId() {
        return muxInfoId;
    }

    public void setMuxInfoId(int muxInfoId) {
        this.muxInfoId = muxInfoId;
    }


    /* util function */
  /*  public boolean isUserDelete() {
        return ((optionMask & ChannelCommon.SB_VOPT_DELETED_BY_USER) > 0) ? true : false;
    }

    public boolean isVisible() {
        return ((nwMask & ChannelCommon.SB_VNET_VISIBLE) > 0) ? true : false;
    }

    public boolean isEpgVisible() {
        return ((nwMask & ChannelCommon.SB_VNET_EPG) > 0) ? true : false;
    }

    public boolean isRadioService() {
        return ((nwMask & ChannelCommon.SB_VNET_RADIO_SERVICE) > 0) ? true : false;
    }

    public boolean isAnalogService() {
        return ((nwMask & ChannelCommon.SB_VNET_ANALOG_SERVICE) > 0) ? true : false;
    }

    public boolean isTvService() {
        return ((nwMask & ChannelCommon.SB_VNET_TV_SERVICE) > 0) ? true : false;
    }

    public void setChannelNameEdited(boolean flag) {
        if (flag) {
            nwMask |= ChannelCommon.SB_VNET_CH_NAME_EDITED;
            optionMask |= ChannelCommon.SB_VOPT_CH_NAME_EDITED;
        } else {
            nwMask &= ~(ChannelCommon.SB_VNET_CH_NAME_EDITED);
            optionMask &= ~(ChannelCommon.SB_VOPT_CH_NAME_EDITED);
        }
    }

    public void setFrequencyEdited(boolean flag) {
        if (flag) {
            nwMask |= ChannelCommon.SB_VNET_FREQ_EDITED;
            optionMask |= ChannelCommon.SB_VOPT_FREQ_EDITED;
        } else {
            nwMask &= ~(ChannelCommon.SB_VNET_FREQ_EDITED);
            optionMask &= ~(ChannelCommon.SB_VOPT_FREQ_EDITED);
        }
    }

    public void setChannelNumberEdited(boolean flag) {
        if (flag) {
            optionMask |= ChannelCommon.SB_VOPT_CH_NUM_EDITED;
        } else {
            optionMask &= ~(ChannelCommon.SB_VOPT_CH_NUM_EDITED);
        }
    }

    public void setChannelDeleted(boolean flag) {
        if (flag) {
            optionMask |= ChannelCommon.SB_VOPT_DELETED_BY_USER;
        } else {
            optionMask &= ~(ChannelCommon.SB_VOPT_DELETED_BY_USER);
        }
    }
    */

    public String toString() {
        return "ChannelInfo [channelDBId=" + channelDBId
                + " , channelId=" + channelId  + " , optionMask=" + optionMask
                 + " , channelNumber="
                + channelNumber + " , serviceName=" + serviceName + "]";
    } 
    
	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeByte(channelDBId);
		dest.writeInt(channelId);
		dest.writeInt(optionMask);
		dest.writeInt(channelNumber);
		dest.writeString(serviceName);
	
	}
	
	public static final Parcelable.Creator<ChannelInfo> CREATOR=new Creator<ChannelInfo>() {

		@Override
		public ChannelInfo[] newArray(int size) {
			return new ChannelInfo[size];
		}

		@Override
		public ChannelInfo createFromParcel(Parcel source) {			
			return new ChannelInfo(source.readByte(),source.readInt(),source.readInt(),source.readInt(),source.readString());
		}
	};    
    

}
